local chuiqi = fk.CreateSkill{
    name = "ym1__chuiqi",
}
Fk:loadTranslationTable{
    ["ym1__chuiqi"] = "垂泣",
    [":ym1__chuiqi"] = "出牌阶段，你可将数量最多花色的手牌依次当【乐不思蜀】对自己使用。你判定区有牌时，你使用牌无距离和次数限制，且使用时弃置判定区内一张牌。",
    ["#ym1__chuiqi"] = "垂泣：将数量最多花色的手牌依次当【乐不思蜀】对自己使用",

    ["$ym1__chuiqi1"] = "凤凰延颈泣交颐，麒麟顿首悲长嘶。",
    ["$ym1__chuiqi2"] = "身居荆楚，心怀故都，伤悲感怀，涕泗横流。",
}
chuiqi:addEffect("active",{
    anim_type = "control",
    prompt = "#ym1__chuiqi",
    card_num = 0,
    target_num = 0,
    can_use = function(self, player)
        return not player:hasDelayedTrick("indulgence") and not table.contains(player.sealedSlots, Player.JudgeSlot) and #table.filter(player:getCardIds(Player.Hand),function (id)
            return Fk:getCardById(id).suit ~= Card.NoSuit
        end) > 0
    end,
    target_filter = Util.FalseFunc,
    card_filter = Util.FalseFunc,
    interaction = function (self, player)
        local suitMapper = { [1] = {}, [2] = {}, [3] = {}, [4] = {} }
        table.forEach(player:getCardIds(Player.Hand), function(id)
            if Fk:getCardById(id).suit ~= Card.NoSuit then
                table.insert(suitMapper[Fk:getCardById(id).suit], id)
            end
        end)
        local maxNum = -1
        local all_suits = {"log_spade", "log_club", "log_heart", "log_diamond"}
        local choices = {}
        for i, j in ipairs(suitMapper) do
            local num = #j
            if num >= maxNum then
                if num > maxNum then
                maxNum = num
                choices = {}
                end
                table.insert(choices, all_suits[i])
            end
        end
        return UI.ComboBox{choices = choices}
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local suitMapper = { [1] = {}, [2] = {}, [3] = {}, [4] = {} }
        table.forEach(player:getCardIds(Player.Hand), function(id)
            if Fk:getCardById(id).suit ~= Card.NoSuit then
                table.insert(suitMapper[Fk:getCardById(id).suit], id)
            end
        end)
        local all_suits = {"log_spade", "log_club", "log_heart", "log_diamond"}
        local cid = suitMapper[table.indexOf(all_suits, self.interaction.data)]
        for _, value in ipairs(cid) do
            local c = Fk:cloneCard("indulgence")
            c:addSubcards({value})
            c.skillName = chuiqi.name
            room:useCard{
                from = player,
                tos = {player},
                card = c,
            }
        end
    end,
})
chuiqi:addEffect(fk.CardUsing,{
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(chuiqi.name) and #player:getCardIds("j") > 0 and data.card.skillName ~= chuiqi.name
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local cards = player:getCardIds("j")
        if player.dead or #cards == 0 then return false end
        if #cards > 1 then
            cards = {room:askToChooseCard(player, {
                target = player,
                flag = "j",
                skill_name = chuiqi.name,
            })}
        end
        if #cards > 0 then
            event:setCostData(self, {cards = cards})
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:throwCard(event:getCostData(self).cards, chuiqi.name, player, player)
    end,
})
chuiqi:addEffect(fk.PreCardUse,{
    can_refresh = function(self, event, target, player, data)
        return target == player and player:hasSkill(chuiqi.name) and #player:getCardIds("j") > 0
    end,
    on_refresh = function(self, event, target, player, data)
        data.extraUse = true
    end,
})
chuiqi:addEffect("targetmod", {
    bypass_times = function(self, player, skill, scope, card, to)
        return card and player:hasSkill(chuiqi.name) and #player:getCardIds("j") > 0
    end,
    bypass_distances = function(self, player, skill, card, to)
        return card and player:hasSkill(chuiqi.name) and #player:getCardIds("j") > 0
    end,
})
return chuiqi